<template>
  <n-form
      style="margin-top: 24px"
      ref="formRef"
      :model="form"
      :rules="rules"
      label-placement="top"
      label-width="120"
      require-mark-placement="right-hanging"
  >

    <n-form-item label="编码" path="sn">
      <n-input v-model:value="form.sn" placeholder="请输入编码"></n-input>
    </n-form-item>
    <n-form-item label="功能描述" path="">
      <n-input v-model:value="form.briefInfo" placeholder="请输入功能描述"></n-input>
    </n-form-item>
    <n-form-item label="serviceClass" path="serviceClass">
      <n-input v-model:value="form.serviceClass" placeholder="请输入所属类名"></n-input>
    </n-form-item>
    <n-form-item label="serviceMethod" path="serviceMethod">
      <n-input v-model:value="form.serviceMethod" placeholder="请输入方法名"></n-input>
    </n-form-item>
<!--    <n-form-item label="servicePackageClassMethod" path="servicePackageClassMethod">-->
<!--      <n-input v-model:value="form.servicePackageClassMethod" placeholder="请输入所属类名方法名"></n-input>-->
<!--    </n-form-item>-->


  </n-form>
</template>

<script setup>
import {onMounted, reactive, ref, watch} from 'vue'
import {JBoltApi} from '@/service/request'

const props = defineProps({
  id: {
    type: String
  }
})


const formRef = ref(null)

const form = ref({
  id: '',
  sn: "",
  type: "",
  briefInfo: "",
  serviceClass: "",
  serviceMethod: "",
  paramCount: 0,
  enable: true,
  createTime: "",
  servicePackageClassMethod: ""
})

const rules = {
  type: {
    required: true,
    message: '请选择资源类型',
    trigger: 'change'
  },
  name: {
    required: true,
    message: '请输入资源名称',
    trigger: 'change'
  }
}





async function submit(fun) {
  await formRef.value?.validate()

  console.debug('提交表单', form.value)

  let url = props.id ? '/aiFunction/update' : '/aiFunction/add'

  await JBoltApi.tryPost(url, form.value)


  if (fun) {
    fun()
  }

  return true
}

defineExpose({
  submit
})


</script>

<style scoped lang="scss">
.text_tip {
  font-size: 12px;
  color: #999;
}
</style>